#!/bin/bash

if [ $# -lt 4 ] 
then 
    echo "$0  <interface> <target_ip> <domain_file(in)> <dump_file(out)>"
    exit
fi

INTERFACE=$1
TARGET_IP=$2
DOMAIN_FILE=$3 
DUMP_FILE=$4

TCPDUMP=/usr/sbin/tcpdump
DIG=/usr/bin/dig
FDIG="./fdig.py"

echo "Start probe domain name"
echo $TCPDUMP -i $INTERFACE -s0  -U -w $DUMP_FILE  src host $TARGET_IP  
$TCPDUMP -i $INTERFACE -s0 -U -w $DUMP_FILE src host $TARGET_IP & 
LASTPID=$!
	
sleep 1
    
echo $FDIG  $DOMAIN_FILE $TARGET_IP
$FDIG  $DOMAIN_FILE $TARGET_IP
sleep 3

#Repeat 
$FDIG  $DOMAIN_FILE $TARGET_IP
sleep 5

kill -9 $LASTPID
sleep 1 

echo "Probe and dump finished, the dump file: $DUMP_FILE"
